import  Vue from "vue"

export default{
	 scan(){
		uni.scanCode({
			success: (res) =>{
				let url=res.result;
				let params=this.getQueryString(url);
				console.log(params,"params")
				if(params.path && params.sid){
					console.log( params.path+Vue.prototype.$u.queryParams(params))
					uni.navigateTo({
						url: params.path+Vue.prototype.$u.queryParams(params)
					})
				}
			}
		});
	},
	getQueryString(url) {
	  let requestParams = {};
	  if (url.indexOf("?") !== -1) {
		let str = url.substr(url.indexOf("?") + 1); //截取?后面的内容作为字符串
		let strs = str.split("&"); //将字符串内容以&分隔为一个数组
		for (let i = 0; i < strs.length; i++) {
		  requestParams[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
		  // 将数组元素中'='左边的内容作为对象的属性名，'='右边的内容作为对象对应属性的属性值
		}
	  }
	  return requestParams;
	
	}
}








